﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace ConfigureNZBLoader
{
    public partial class TestQueryString : Form
    {
        private string _Query = "";
        public string Query
        {
            get
            {
                return _Query;
            }
            set
            {
                _Query = value;
            }
        }

        public TestQueryString()
        {
            InitializeComponent();
        }

        private void btnCancel_Click(object sender, EventArgs e)
        {
            Close();
        }

        private void btnOk_Click(object sender, EventArgs e)
        {
            Query = txtQuery.Text;
            DialogResult = DialogResult.OK;
            Close();
        }

        private void btnTest_Click(object sender, EventArgs e)
        {
            try
            {
                Util.QueryParser.Token.IToken t = Util.QueryParser.Parser.BuildTokenTree(txtQuery.Text);
                if (t.Evaluate(txtTest.Text))
                {
                    lblOutput.Text = "\n\n\nResult: TRUE";
                }
                else
                {
                    lblOutput.Text = "\n\n\nResult: FALSE";
                }
            }
            catch (Exception ex)
            {
                lblOutput.Text = "\n\n\n" + ex.ToString();
            }

        }

        private void TestQueryString_Load(object sender, EventArgs e)
        {
            txtQuery.Text = Query;
        }

    }
}
